﻿// **********************************************************************
//
// Author: KingSley
// Email:3268374537@qq.com
// Created:	2018/8/1   10:35
// Introduce: 对怪物属性的控制与管理
//
// **********************************************************************
using UnityEngine;

namespace KingSley
{
    [AddComponentMenu("KingARPG/属性数据/怪物属性控制器")]
    public class MonsterAttributeControl : MonoSingleton<PlayerAttributeControl>
    {
        /// <summary>
        /// 各类的实例对象
        /// </summary>
        public MonsterBaseAttribute MonsterBaseStatus;
        public MonsterAdditionAttribute MonsterAddStatus;
        public MonsterCurAttribute MonsterCurStatus;
        public MonsterSumAttribute MonsterSumStatus;

        /// <summary>
        /// 各类动作的速度
        /// </summary>
        public float MonsterRunSpeed;
        public float MonsterWalkSpeed;
        public float MonsterTurnSpeed;
        public float MonsterBackSpeed;

        public Animator MonsterAnimator;
        
        /// <summary>
        /// 更新属性值
        /// </summary>
        void UpdateAttribute()
        {
            MonsterSumStatus.Strong = MonsterBaseStatus.Strong + MonsterAddStatus.Strong;
            MonsterSumStatus.Intelligence = MonsterBaseStatus.Intelligence + MonsterAddStatus.Intelligence;
            MonsterSumStatus.Agility = MonsterBaseStatus.Agility + MonsterAddStatus.Agility;
            MonsterSumStatus.Power = MonsterBaseStatus.Power + MonsterAddStatus.Power;

            MonsterSumStatus.Attack = MonsterBaseStatus.Attack + MonsterAddStatus.Attack + Mathf.FloorToInt(MonsterSumStatus.Strong * 0.2f);
            MonsterSumStatus.Defend = MonsterBaseStatus.Defend + MonsterAddStatus.Defend + Mathf.FloorToInt(MonsterSumStatus.Power * 0.2f);

            MonsterSumStatus.HP = MonsterBaseStatus.HP + MonsterAddStatus.HP + Mathf.FloorToInt(MonsterSumStatus.Strong * 0.4f);
            MonsterSumStatus.MP = MonsterBaseStatus.MP + MonsterAddStatus.MP + Mathf.FloorToInt(MonsterSumStatus.Intelligence * 0.4f);
            MonsterSumStatus.AttackSpeed = MonsterBaseStatus.AttackSpeed + MonsterAddStatus.AttackSpeed + Mathf.FloorToInt(MonsterSumStatus.Agility * 0.2f);
            MonsterSumStatus.MoveSpeed = MonsterBaseStatus.MoveSpeed + MonsterAddStatus.MoveSpeed + Mathf.FloorToInt(MonsterSumStatus.Agility * 0.3f);
            MonsterSumStatus.RotationSpeed = MonsterBaseStatus.RotationSpeed + MonsterAddStatus.RotationSpeed + Mathf.FloorToInt(MonsterSumStatus.Agility * 0.2f);
            MonsterSumStatus.CriticalRate = MonsterBaseStatus.CriticalRate + MonsterAddStatus.CriticalRate;
            MonsterSumStatus.CriticalDamage = MonsterBaseStatus.CriticalDamage + MonsterAddStatus.CriticalDamage;

            MonsterCurStatus.CurAttack = MonsterSumStatus.Attack;
            MonsterCurStatus.CurDefend = MonsterSumStatus.Defend;
            MonsterCurStatus.CurStrong = MonsterSumStatus.Strong;
            MonsterCurStatus.CurIntelligence = MonsterSumStatus.Intelligence;
            MonsterCurStatus.CurAgility = MonsterSumStatus.Agility;
            MonsterCurStatus.CurPower = MonsterSumStatus.Power;
            MonsterCurStatus.CurCriticalRate = MonsterSumStatus.CriticalRate;
            MonsterCurStatus.CurCriticalDamage = MonsterSumStatus.CriticalDamage;
        }

        /// <summary>
        /// 检测HP、MP的当前值是否超出规定，每帧调用
        /// </summary>
        void CheckHPMP()
        {
            AnimatorStateInfo MonsterCurrentState = MonsterAnimator.GetCurrentAnimatorStateInfo(0);
            if (!MonsterCurrentState.IsName("Base.MonsterDeath"))
            {
                MonsterCurStatus.CurHP += Mathf.FloorToInt(MonsterBaseStatus.HPRecoverPerSecond * 0.33f);
                MonsterCurStatus.CurMP += Mathf.FloorToInt(MonsterBaseStatus.MPRecoverPerSecond * 0.50f);
            }
            else
            {
                MonsterCurStatus.CurHP = 0;
                MonsterCurStatus.CurMP = 0;
            }
            if (MonsterCurStatus.CurHP < 0)
                MonsterCurStatus.CurHP = 0;
            if (MonsterCurStatus.CurMP < 0)
                MonsterCurStatus.CurMP = 0;
            if (MonsterCurStatus.CurHP >= MonsterSumStatus.HP)
                MonsterCurStatus.CurHP = MonsterSumStatus.HP;
            if (MonsterCurStatus.CurMP >= MonsterSumStatus.MP)
                MonsterCurStatus.CurMP = MonsterSumStatus.MP;
        }
    }
}